package com.ycsj.goldmedalnewconcept.activity;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import android.annotation.SuppressLint;
import android.app.AlertDialog.Builder;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.AssetManager;
import android.graphics.Bitmap;
import android.graphics.Bitmap.CompressFormat;
import android.graphics.BitmapFactory;
import android.os.Build;
import android.os.Bundle;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import cn.sharesdk.framework.Platform;
import cn.sharesdk.framework.Platform.ShareParams;
import cn.sharesdk.onekeyshare.OnekeyShare;
import cn.sharesdk.onekeyshare.ShareContentCustomizeCallback;
import cn.sharesdk.sina.weibo.SinaWeibo;
import com.google.gson.Gson;
import com.lidroid.xutils.HttpUtils;
import com.lidroid.xutils.exception.HttpException;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.callback.RequestCallBack;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import com.mob.MobSDK;
import com.readystatesoftware.systembartint.SystemBarTintManager;
import com.squareup.okhttp.Call;
import com.squareup.okhttp.Callback;
import com.squareup.okhttp.OkHttpClient;
import com.squareup.okhttp.Request;
import com.squareup.okhttp.Response;
import com.ycsj.goldmedalnewconcept.R;
import com.ycsj.goldmedalnewconcept.bean.ClassThirdListInfo;
import com.ycsj.goldmedalnewconcept.bean.ClassThirdResq;
import com.ycsj.goldmedalnewconcept.bean.ClassThirdResq2;
import com.ycsj.goldmedalnewconcept.bean.GetCollectResq;
import com.ycsj.goldmedalnewconcept.bean.UserVedioListInfo;
import com.ycsj.goldmedalnewconcept.bean.mineBasicInfoResp2;
import com.ycsj.goldmedalnewconcept.bean.timeresq;
import com.ycsj.goldmedalnewconcept.constant.ConfigConstant;
import com.ycsj.goldmedalnewconcept.constant.NetConstant;
import com.ycsj.goldmedalnewconcept.utils.MyWebViewClient;
import com.ycsj.goldmedalnewconcept.utils.SPUtils;

@SuppressLint("NewApi")
public class ClassThirdActivity extends BaseJpStarActivity {

	private ListView lv_class_second;
	protected ArrayList<ClassThirdListInfo> list = new ArrayList<ClassThirdListInfo>();
	private ImageView iv_share;
	private TextView tv_teacher;

	private static final int MSG_TOAST = 1;
	private static final int MSG_ACTION_CCALLBACK = 2;
	private static final int MSG_CANCEL_NOTIFY = 3;

	// sdcard中的图片名称
	private static final String FILE_NAME = "/share_pic.jpg";
	public static String TEST_IMAGE;
	private ProgressBar mprogressBar;
	private TextView tv_word_title;
	private TextView tv_word_back;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		getWindow().requestFeature(Window.FEATURE_PROGRESS);
		super.onCreate(savedInstanceState);
		setContentView(R.layout.fragment_class_second);

//		IWXAPI wxapi = WXAPIFactory.createWXAPI(ClassThirdActivity.this,
//				"wx87beee1b911fdac7");
		handler = new Handler();
		OkHttpClient mOkHttpClient = new OkHttpClient();
		// 创建一个Request
		final Request request = new Request.Builder().url(
				NetConstant.USERFAVOR
						+ "/GetUserVedioList.aspx?account="
						+ SPUtils.getString(ClassThirdActivity.this,
								ConfigConstant.USERNAME)
						+ "&usertoken="
						+ SPUtils.getString(ClassThirdActivity.this,
								ConfigConstant.USERTOKEN)).build();
		// new call
		Call call = mOkHttpClient.newCall(request);
		// 请求加入调度
		call.enqueue(new Callback() {

			@Override
			public void onFailure(Request arg0, IOException arg1) {
				// TODO Auto-generated method stub
				
			}

			@Override
			public void onResponse(Response arg0) throws IOException {
				// TODO Auto-generated method stub
				// Toast.makeText(getActivity(), "取消成功", 0).show();
				String json = arg0.body().string();
				// 使用Gson把json解析成对象
				// 1 得到gson对象

				Log.i("test", "liebiao" + json);
				Gson gson = new Gson();
				// // 2 使用gson对象的方法
				if ("1".equals(gson.fromJson(json, mineBasicInfoResp2.class).result)
						|| "2".equals(gson
								.fromJson(json, ClassThirdResq2.class).RESULTTYPE)) {
					// Log.e("arg0", "34"+json.toString());
					Intent intent = new Intent(ClassThirdActivity.this,
							LoginActivity.class);
					startActivity(intent);
					finish();
				} else {

					GetCollectResq getCollectResq = gson.fromJson(json,
							GetCollectResq.class);
					if (!UserVedioIdList.isEmpty()) {
						UserVedioIdList.removeAll(UserVedioIdList);
					}
					if (!getCollectResq.VIDEO_LIST.isEmpty()) {
						for (UserVedioListInfo i : getCollectResq.VIDEO_LIST) {
							UserVedioIdList.add(i.VEDIO_ID);
						}
					}
					if (!UserVedioIdList.isEmpty()) {
						for (int i = 0; i < UserVedioIdList.size(); i++) {

							if (lESSON_ID.equals(UserVedioIdList.get(i))) {
								handler.postDelayed(new Runnable() {

									@Override
									public void run() {
										// TODO Auto-generated method stub
										cb_collect.setChecked(true);

									}
								}, 0);
							}
						}
					}
				}
			}

		});


		SystemBarTintManager tintManager = new SystemBarTintManager(this);
		tintManager.setStatusBarTintEnabled(true);
		tintManager.setStatusBarTintResource(R.color.base_color);

		mprogressBar = (ProgressBar) findViewById(R.id.mProgress);
		tv_class_title = (TextView) findViewById(R.id.tv_class_title);
		tv_content = (TextView) findViewById(R.id.tv_content);
		tv_teacher = (TextView) findViewById(R.id.tv_teacher);
		iv_share = (ImageView) findViewById(R.id.iv_share);
		cb_collect = (CheckBox) findViewById(R.id.cb_collect);
		tv_word_back = (TextView) findViewById(R.id.tv_word_back);
		AssetManager mgr = getAssets();// 得到AssetManager

		initViews();
		initWebView();

		if (getPhoneAndroidSDK() >= 14) {// 4.0需打开硬件加速
			getWindow().setFlags(0x1000000, 0x1000000);
		}

		if (!SPUtils.getBoolean(ClassThirdActivity.this,
				ConfigConstant.IS_LOGIN_ON)) {
			// Toast.makeText(getActivity(), "IS_LOGIN_ON", 0).show();
			cb_collect.setClickable(false);
			cb_collect.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					Toast.makeText(ClassThirdActivity.this, "没有登录，不能收藏哦！", 0)
							.show();
			cb_collect.setChecked(false);
				}
			});
		} else {
			cb_collect.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {

					if (((CheckBox) v).isChecked()) {

						OkHttpClient mOkHttpClient = new OkHttpClient();
						// 创建一个Request
						final Request request = new Request.Builder().url(
								NetConstant.USERFAVOR
										+ "/SaveUserVedio.aspx?account="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERNAME)
										+ "&usertoken="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERTOKEN)
										+ "&vedioid=" + lESSON_ID).build();
						// new call
						Call call = mOkHttpClient.newCall(request);
						call.enqueue(new Callback() {



							@Override
							public void onFailure(Request arg0, IOException arg1) {
								// TODO Auto-generated method stub
								
							}

							@Override
							public void onResponse(Response arg0)
									throws IOException {
								// TODO Auto-generated method stub
								String json = arg0.body().string();
								// 使用Gson把json解析成对象
								// 1 得到gson对象
								Log.i("test", json);

								handler.postDelayed(new Runnable() {

									@Override
									public void run() {
										// TODO Auto-generated method
										// stub
										cb_collect.setChecked(true);
										Toast.makeText(ClassThirdActivity.this,
												"收藏成功", 0).show();
									}
								}, 100);

								UserVedioIdList.add(lESSON_ID);
							}

							
						});

						Log.e("test",
								"SaveUserVedio-=="
										+ NetConstant.USERFAVOR
										+ "/SaveUserVedio.aspx?account="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERNAME)
										+ "&usertoken="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERTOKEN)
										+ "&vedioid=" + lESSON_ID);

					} else {
						OkHttpClient mOkHttpClient = new OkHttpClient();
						// 创建一个Request
						final Request request = new Request.Builder().url(
								NetConstant.USERFAVOR
										+ "/CancelUserVedio.aspx?account="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERNAME)
										+ "&usertoken="
										+ SPUtils.getString(
												ClassThirdActivity.this,
												ConfigConstant.USERTOKEN)
										+ "&vedioid=" + lESSON_ID).build();
						// new call
						Call call = mOkHttpClient.newCall(request);
						// 请求加入调度
						call.enqueue(new Callback() {


							@Override
							public void onFailure(Request arg0, IOException arg1) {
								// TODO Auto-generated method stub
								
							}

							@Override
							public void onResponse(Response arg0)
									throws IOException {
								// TODO Auto-generated method stub
								String json = arg0.body().string();
								// 使用Gson把json解析成对象
								// 1 得到gson对象

								Log.i("test", json);

								for (int i = 0; i < UserVedioIdList.size(); i++) {

									if (lESSON_ID.equals(UserVedioIdList.get(i))) {
										UserVedioIdList.remove(i);
										handler.postDelayed(new Runnable() {

											@Override
											public void run() {
												// TODO Auto-generated method
												// stub
												cb_collect.setChecked(false);
												Toast.makeText(
														ClassThirdActivity.this,
														"取消成功", 0).show();
											}
										}, 100);

									}
								}
							}
						});
					}
				}
			});
		}

		lESSON_ID = getIntent().getStringExtra("lESSON_ID");
		final String LESSON_NAME = getIntent().getStringExtra("LESSON_NAME");

		tv_class_title.setText(LESSON_NAME);

		HttpUtils httpUtils = new HttpUtils();
		httpUtils.send(
				HttpMethod.GET,
				NetConstant.MINICLASS
						+ "/LevelThree.aspx?lessonid="
						+ lESSON_ID
						+ "&account="
						+ SPUtils.getString(ClassThirdActivity.this,
								ConfigConstant.USERNAME)
						+ "&usertoken="
						+ SPUtils.getString(ClassThirdActivity.this,
								ConfigConstant.USERTOKEN), callBack);

		tv_word_back.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				finish();
			}
		});
		// }

		iv_share.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
//				ShareSDK.initSDK(ClassThirdActivity.this);
				MobSDK.init(ClassThirdActivity.this ,"12c24ea0b59b0","aae63565fbd69b1acbfcdd0d5ac0b35c");
				OnekeyShare oks = new OnekeyShare();
				// 关闭sso授权
				oks.disableSSOWhenAuthorize();
				oks.setShareContentCustomizeCallback(new ShareContentCustomizeCallback() {
					
					@Override
					public void onShare(Platform platform, ShareParams paramsToShare) {
						if(SinaWeibo.NAME.equals(platform.getName())){
							// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
							paramsToShare.setTitle(getString(R.string.share));
							// titleUrl是标题的网络链接，仅在人人网和QQ空间使用
							paramsToShare.setTitleUrl(list.get(0).WEB_URL);
							// text是分享文本，所有平台都需要这个字段
							String url=list.get(0).WEB_URL;
							paramsToShare.setText("英才世家教育咨询有限公司"+url);
							// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
							// oks.setImagePath();//确保SDcard下面存在此张图片
							// oks.seti
							// url仅在微信（包括好友和朋友圈）中使用
							paramsToShare.setUrl(list.get(0).WEB_URL);
							// 微信分享必须设置否则发送文本信息
							// oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
							paramsToShare.setImageUrl("http://139.129.57.83:8080/Appandroid/applogo.png");
							// comment是我对这条分享的评论，仅在人人网和QQ空间使用
							paramsToShare.setComment("");
							// site是分享此内容的网站名称，仅在QQ空间使用
							paramsToShare.setSite(getString(R.string.app_name));
							// siteUrl是分享此内容的网站地址，仅在QQ空间使用
							paramsToShare.setSiteUrl(list.get(0).WEB_URL);
						  
						}else{
							paramsToShare.setShareType(Platform.SHARE_VIDEO);
							// title标题，印象笔记、邮箱、信息、微信、人人网和QQ空间使用
							paramsToShare.setTitle("英才世家教育咨询有限公司");
							// titleUrl是标题的网络链接，仅在人人网和QQ空间使用
							paramsToShare.setTitleUrl(list.get(0).WEB_URL);
							// text是分享文本，所有平台都需要这个字段
							String url=list.get(0).WEB_URL;
							paramsToShare.setText("我正在使用金牌君学习,"+LESSON_NAME+"重难点视频分享,一起来学习吧,请前往应用宝搜索金牌君下载");
							// imagePath是图片的本地路径，Linked-In以外的平台都支持此参数
							// oks.setImagePath();//确保SDcard下面存在此张图片
							// oks.seti
							// url仅在微信（包括好友和朋友圈）中使用
							paramsToShare.setUrl(list.get(0).WEB_URL);
							// 微信分享必须设置否则发送文本信息
							// oks.setImageUrl("http://f1.sharesdk.cn/imgs/2014/02/26/owWpLZo_638x960.jpg");
							paramsToShare.setImageUrl("http://139.129.57.83:8080/Appandroid/applogo.png");
							// comment是我对这条分享的评论，仅在人人网和QQ空间使用
							paramsToShare.setComment("");
							// site是分享此内容的网站名称，仅在QQ空间使用
							paramsToShare.setSite(getString(R.string.app_name));
							// siteUrl是分享此内容的网站地址，仅在QQ空间使用
							paramsToShare.setSiteUrl(list.get(0).WEB_URL);
						}
					}
			 	});
				// 分享时Notification的图标和文字 2.5.9以后的版本不调用此方法
				// oks.setNotification(R.drawable.ic_launcher,
				// getString(R.string.app_name));
				

				// 启动分享GUI
				oks.show(ClassThirdActivity.this);

			}
		});
		new Thread() {
			public void run() {
				initImagePath();
			}
		}.start();
	}

	@Override
	public void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
		if (!"".equals(SPUtils.getString(ClassThirdActivity.this,
				ConfigConstant.USERNAME))) {
			String gradeid = String.valueOf(lESSON_ID).substring(0, 4);
			HttpUtils httpUtils2 = new HttpUtils();
			httpUtils2.send(
					HttpMethod.GET,
					NetConstant.USERONLINE
							+ "InitInterfaceBegin.aspx?msg=1&type=5&account="
							+ SPUtils.getString(ClassThirdActivity.this,
									ConfigConstant.USERNAME) + "&gradeid="
							+ gradeid + "&lessonid=" + lESSON_ID, callBackTime);
		}
	}

	private RequestCallBack<String> callBack = new RequestCallBack<String>() {

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			String json = responseInfo.result;
			// 使用Gson把json解析成对象
			// 1 得到gson对象

			 Log.i("testlogin", json);

			Gson gson = new Gson();

			if ("1".equals(gson.fromJson(json, mineBasicInfoResp2.class).result)
					|| "2".equals(gson.fromJson(json, ClassThirdResq2.class).RESULTTYPE)) {
				// Log.e("arg0", "34"+json.toString());
				Intent intent = new Intent(ClassThirdActivity.this,
						LoginActivity.class);
				startActivity(intent);
				finish();
			} else {
				// // 2 使用gson对象的方法
				ClassThirdResq classThirdResq = gson.fromJson(json,
						ClassThirdResq.class);
				list = classThirdResq.LIST;
				// mWebView.loadUrl("http://139.129.57.83:8080/html5/page01.html");
				// if(!NetUtils.isMobileConnected(getActivity())){

				mWebView.loadUrl(list.get(0).WEB_URL);

				 Log.e("test", "WEB_URL"+list.get(0).WEB_URL);
				// Log.e("home", ""+list.get(0).WEB_URL);
				// }else{
				// showLoadWebview();
				// mWebView.loadUrl(list.get(0).WEB_URL);
				// }
				String s = list.get(0).YC_DESC.replace("￠", "\n");
				tv_content.setMovementMethod(new ScrollingMovementMethod(

				));
				tv_content.setText(s);
				String substring = list.get(0).VEDIO_ID.substring(0, 4);
				if ("3001".equals(substring)) {
					tv_teacher.setText("主讲老师 : Vivi");
				} else if ("3002".equals(substring)) {
					tv_teacher.setText("主讲老师 : Vivi");
				} else if ("3003".equals(substring)) {
					tv_teacher.setText("主讲老师 : Psyche");
				} else if ("3004".equals(substring)) {
					tv_teacher.setText("主讲老师 : Psyche");
				}
			}
		}

		@Override
		public void onFailure(HttpException error, String msg) {

		}
	};

	protected RequestCallBack<String> callBackCollect = new RequestCallBack<String>() {

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {

			String json = responseInfo.result;
			// 使用Gson把json解析成对象
			// 1 得到gson对象
			//
			Log.i("test", json);
			Toast.makeText(ClassThirdActivity.this, "收藏成功", Toast.LENGTH_SHORT).show();

			cb_collect.setChecked(true);

			UserVedioIdList.add(lESSON_ID);
		}

		@Override
		public void onFailure(HttpException error, String msg) {
			// TODO Auto-generated method stub

		}
	};

	private ArrayList<UserVedioListInfo> collect_VIDEO_LIST = new ArrayList<UserVedioListInfo>();
	private ArrayList<String> UserVedioIdList = new ArrayList<String>();

	private FrameLayout mFullscreenContainer;
	private FrameLayout mContentView;
	private View mCustomView = null;
	private WebView mWebView;
	private Button bt_qrscan;
	private TextView tv_class_title;
	private TextView tv_content;
	private CheckBox cb_collect;
	private String lESSON_ID;

	private void initViews() {
		// mFullscreenContainer = (FrameLayout)
		// findViewById(R.id.fullscreen_custom_content);
		mContentView = (FrameLayout) findViewById(R.id.main_content);
		mWebView = (WebView) findViewById(R.id.webview_player);

		Button videolandport = (Button) findViewById(R.id.video_landport);

		videolandport.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				Intent intent = new Intent(ClassThirdActivity.this,
						ClassThirdHorizontalActivity.class);
				intent.putExtra("URL", list.get(0).WEB_URL);
				startActivity(intent);
			}
		});
	}

	private void initWebView() {
		
		
	     
		WebSettings settings = mWebView.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setPluginState(PluginState.ON);
		// settings.setPluginsEnabled(true);
		settings.setAllowFileAccess(true);
		settings.setLoadWithOverviewMode(true);
		if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){  
			settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);  
	     } 
		
		
		mWebView.setWebViewClient(new MyWebViewClient(mprogressBar));
		mWebView.setWebChromeClient(new WebChromeClient() {
			@Override
			public void onProgressChanged(WebView view, int newProgress) {
				// TODO Auto-generated method stub
				// MainActivity.this.setProgress(newProgress * 100);
				mprogressBar.setProgress(newProgress);
			}
			
			
		});
	}

	class MyWebChromeClient extends WebChromeClient {

		private CustomViewCallback mCustomViewCallback;
		private int mOriginalOrientation = 1;

		@Override
		public void onShowCustomView(View view, CustomViewCallback callback) {
			// TODO Auto-generated method stub
			onShowCustomView(view, mOriginalOrientation, callback);
			super.onShowCustomView(view, callback);

		}

		public void onShowCustomView(View view, int requestedOrientation,
				CustomViewCallback callback) {
			if (mCustomView != null) {
				callback.onCustomViewHidden();
				return;
			}

		}

		@SuppressLint("WrongConstant")
		public void onHideCustomView() {
			mContentView.setVisibility(View.VISIBLE);
			if (mCustomView == null) {
				return;
			}
			mCustomView.setVisibility(View.GONE);
			mFullscreenContainer.removeView(mCustomView);
			mCustomView = null;
			mFullscreenContainer.setVisibility(View.GONE);
			try {
				mCustomViewCallback.onCustomViewHidden();
			} catch (Exception e) {
			}
			// Show the content view.

			ClassThirdActivity.this
					.setRequestedOrientation(mOriginalOrientation);
		}

	}


	public static int getPhoneAndroidSDK() {
		// TODO Auto-generated method stub
		int version = 0;
		try {
			version = Integer.valueOf(Build.VERSION.SDK);
		} catch (NumberFormatException e) {
			e.printStackTrace();
		}
		return version;

	}

	// 把图片从drawable复制到sdcard中
	private void initImagePath() {
		try {
			if (Environment.MEDIA_MOUNTED.equals(Environment
					.getExternalStorageState())
					&& Environment.getExternalStorageDirectory().exists()) {
				TEST_IMAGE = Environment.getExternalStorageDirectory()
						.getAbsolutePath() + FILE_NAME;
			} else {
				TEST_IMAGE = getApplication().getFilesDir().getAbsolutePath()
						+ FILE_NAME;
			}
			File file = new File(TEST_IMAGE);
			if (!file.exists()) {
				file.createNewFile();
				Bitmap pic = BitmapFactory.decodeResource(getResources(),
						R.drawable.pic);
				FileOutputStream fos = new FileOutputStream(file);
				pic.compress(CompressFormat.JPEG, 100, fos);
				fos.flush();
				fos.close();
			}
		} catch (Throwable t) {
			t.printStackTrace();
			TEST_IMAGE = null;
		}
	}

	@Override
	public void onPause() {
		// TODO Auto-generated method stub
		super.onPause();

		HttpUtils httpUtils2 = new HttpUtils();
		httpUtils2.send(
				HttpMethod.GET,
				NetConstant.USERONLINE
						+ "SaveInterfaceEnd.aspx?msg=1&rid="
						+ rid
						+ "&account="
						+ SPUtils.getString(ClassThirdActivity.this,
								ConfigConstant.USERNAME), callBackTimefinish);

		mWebView.reload();
	}

	@Override
	protected void onStop() {
		// TODO Auto-generated method stub
		super.onStop();
		Log.e("testlogin", "onStop");
	}

	@Override
	public void onDestroy() {
		super.onDestroy();

	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
			// 这里重写返回键
			// Toast.makeText(getActivity(), "fibnish", 0).show();
			finish();
			return true;
		}
		return false;
	}

	public boolean handleMessage(Message msg) {
		switch (msg.what) {
		case MSG_TOAST: {
			String text = String.valueOf(msg.obj);
			Toast.makeText(ClassThirdActivity.this, text, Toast.LENGTH_SHORT)
					.show();
		}
			break;
		case MSG_ACTION_CCALLBACK: {
			switch (msg.arg1) {
			case 1: { // 成功
				showNotification(2000, getString(R.string.share_completed));
			}
				break;
			case 2: { // 失败
			}
			// break;
			case 3: { // 取消
				showNotification(2000, getString(R.string.share_canceled));
			}
				break;
			}
		}
			break;
		case MSG_CANCEL_NOTIFY: {
			NotificationManager nm = (NotificationManager) msg.obj;
			if (nm != null) {
				nm.cancel(msg.arg1);
			}
		}

			break;
		}
		return false;
	}

	// 在状态栏提示分享操作
	@SuppressWarnings("deprecation")
	private void showNotification(long cancelTime, String text) {
		try {

			Context app = getApplicationContext();
			NotificationManager nm = (NotificationManager) app
					.getSystemService(Context.NOTIFICATION_SERVICE);
			final int id = Integer.MAX_VALUE / 13 + 1;
			nm.cancel(id);

			long when = System.currentTimeMillis();
			Notification notification = new Notification(
					R.drawable.ic_launcher, text, when);
			PendingIntent pi = PendingIntent.getActivity(app, 0, new Intent(),
					0);
//			Builder builder = new Notification.Builder(ClassThirdActivity.this);  
			
			
//			notification.setLatestEventInfo(app, "sharesdk test", text, pi);
			
			
			notification.flags = Notification.FLAG_AUTO_CANCEL;
			nm.notify(id, notification);

			if (cancelTime > 0) {
				Message msg = new Message();
				msg.what = MSG_CANCEL_NOTIFY;
				msg.obj = nm;
				msg.arg1 = id;
				// UIHandler.sendMessageDelayed(msg, cancelTime, this);
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public void showLoadWebview() {
		Builder builder = new Builder(ClassThirdActivity.this);
		builder.setTitle("当前网络提醒");
		builder.setMessage("当前网络环境为手机网络，注意流量使用！ 是否进行修改？");
		builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
			public void onClick(DialogInterface dialog, int which) {
				if (Build.VERSION.SDK_INT > 10) {
					// 3.0以上打开设置界面，也可以直接用ACTION_WIRELESS_SETTINGS打开到wifi界面
					startActivity(new Intent(
							android.provider.Settings.ACTION_SETTINGS));
				} else {
					startActivity(new Intent(
							android.provider.Settings.ACTION_WIRELESS_SETTINGS));
				}
				dialog.cancel();
			}
		});

		builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
			@Override
			public void onClick(DialogInterface dialog, int which) {
				dialog.cancel();

			}
		});
		builder.show();
	}

	private String rid;
	private RequestCallBack<String> callBackTime = new RequestCallBack<String>() {

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			// TODO Auto-generated method stub
			String json = responseInfo.result;
			// 使用Gson把json解析成对象
			// 1 得到gson对象

			// Log.i("testtime", json.toString());

			Gson gson = new Gson();
			timeresq fromJson = gson.fromJson(json, timeresq.class);
			rid = fromJson.rid;
		}

		@Override
		public void onFailure(HttpException error, String msg) {
			// TODO Auto-generated method stub
			rid = "";
		}
	};

	private RequestCallBack<String> callBackTimefinish = new RequestCallBack<String>() {

		@Override
		public void onSuccess(ResponseInfo<String> responseInfo) {
			// TODO Auto-generated method stub
			String json = responseInfo.result;
			// 使用Gson把json解析成对象
			// 1 得到gson对象

			// Log.i("testtime", json.toString());
		}

		@Override
		public void onFailure(HttpException error, String msg) {
			// TODO Auto-generated method stub

		}
	};
	private Handler handler;

}
